/**
 * HeapTester  
 */

public class HeapTester
{

    public static void outputheap(Heap c) {
       System.out.println(c.toString());
    }
    public static void main(String[] args) {

        int isHeapAfterInsertErr = 0;
        int isHeapAfterDeleteMinErr = 0; 
        int getMinErr = 0;
        int heapsize = 0;

        int minVal = -1;
        Heap heap = new Heap();
        
        System.out.println("Insert 5" );
        heap.insert(5);
        heapsize++;
        outputheap(heap);

        if (heap.isHeap() != true )
        {
            isHeapAfterInsertErr++;
            System.out.println("isHeapAfterInsertError");
        }
        minVal = heap.getMin();
        if ( minVal != 5)
        {
            getMinErr++;
            System.out.println("getMinError: getMin returns " + minVal + " instead of 5");
        }

        System.out.println("Insert 8" );
        heap.insert(8);
        heapsize++;
        outputheap(heap);

        if (heap.isHeap() != true )
        {
            isHeapAfterInsertErr++;
            System.out.println("isHeapAfterInsertError");
        }

        minVal = heap.getMin();
        if ( minVal != 5)
        {
            getMinErr++;
            System.out.println("getMinError: getMin returns " + minVal + " instead of 5");
        }


        System.out.println("deleteMin" );
        heap.deleteMin();     
        heapsize--;
        outputheap(heap);

        if (heap.isHeap() != true )
        {
            isHeapAfterDeleteMinErr++;
            System.out.println("isHeapAfterDeleteMinError");

        }

        System.out.println("Insert 5" );
        heap.insert(5);
        heapsize++;
        outputheap(heap);

        if (heap.isHeap() != true )
        {
            isHeapAfterInsertErr++;
            System.out.println("isHeapAfterInsertError");
        }

        minVal = heap.getMin();
        if ( minVal != 5)
        {
            getMinErr++;
            System.out.println("getMinError: getMin returns " + minVal + " instead of 5");
        }

        System.out.println("Insert 1" );
        heap.insert(1);
        heapsize++;
        outputheap(heap);

        if (heap.isHeap() != true )
        {
            isHeapAfterInsertErr++;
            System.out.println("isHeapAfterInsertError");
        }

        System.out.println("Insert 7" );
        heap.insert(7);
        heapsize++;
        outputheap(heap);

        if (heap.isHeap() != true )
        {
            isHeapAfterInsertErr++;
            System.out.println("isHeapAfterInsertError");
        }

        minVal = heap.getMin();
        if ( minVal != 1)
        {
            getMinErr++;
            System.out.println("getMinError: getMin returns " + minVal + " instead of 1");
        }


        System.out.println("deleteMin" );
        heap.deleteMin();     
        heapsize--;
        outputheap(heap);

        if (heap.isHeap() != true )
        {
            isHeapAfterDeleteMinErr++;
            System.out.println("isHeapAfterDeleteMinError");

        }


        System.out.println("Insert 2" );
        heap.insert(2);
        heapsize++;
        outputheap(heap);
        if (heap.isHeap() != true )
        {
            isHeapAfterInsertErr++;
            System.out.println("isHeapAfterInsertError");
        }

        System.out.println("Insert 5" );
        heap.insert(5);
        heapsize++;
        outputheap(heap);

        if (heap.isHeap() != true )
        {
            isHeapAfterInsertErr++;
            System.out.println("isHeapAfterInsertError");
        }

        System.out.println("Insert 9" );
        heap.insert(9);
        heapsize++;
        outputheap(heap);
        if (heap.isHeap() != true )
        {
            isHeapAfterInsertErr++;
            System.out.println("isHeapAfterInsertError");
        }
        minVal = heap.getMin();
        if ( minVal != 2)
        {
            getMinErr++;
            System.out.println("getMinError: getMin returns " + minVal + " instead of 2");
        }

        System.out.println("deleteMin" );
        heap.deleteMin();     
        heapsize--;
        outputheap(heap);
        if (heap.isHeap() != true )
        {
            isHeapAfterDeleteMinErr++;
            System.out.println("isHeapAfterDeleteMinError");

        }

        minVal = heap.getMin();
        if ( minVal != 5)
        {
            getMinErr++;
            System.out.println("getMinError: getMin returns " + minVal + " instead of 5");
        }

        System.out.println("deleteMin" );
        heap.deleteMin();     
        heapsize--;
        outputheap(heap);
        if (heap.isHeap() != true )
        {
            isHeapAfterDeleteMinErr++;
            System.out.println("isHeapAfterDeleteMinError");

        }

        minVal = heap.getMin();
        if ( minVal != 5)
        {
            getMinErr++;
            System.out.println("getMinError: getMin returns " + minVal + " instead of 5");
        }

        System.out.println("deleteMin" );
        heap.deleteMin();     
        heapsize--;
        outputheap(heap);
        if (heap.isHeap() != true )
        {
            isHeapAfterDeleteMinErr++;
            System.out.println("isHeapAfterDeleteMinError");

        }
        minVal = heap.getMin();
        if ( minVal != 7)
        {
            getMinErr++;
            System.out.println("getMinErr: getMin returns " + minVal + " instead of 7");
        }

        System.out.println("deleteMin" );
        heap.deleteMin();     
        heapsize--;
        outputheap(heap);
        if (heap.isHeap() != true )
        {
            isHeapAfterDeleteMinErr++;
            System.out.println("isHeapAfterDeleteMinErr");

        }
        minVal = heap.getMin();
        if ( minVal != 8)
        {
            getMinErr++;
            System.out.println("getMinErr: getMin returns " + minVal + " instead of 8");
        }

        System.out.println("deleteMin" );
        heap.deleteMin();     
        heapsize--;
        outputheap(heap);
        if (heap.isHeap() != true )
        {
            isHeapAfterDeleteMinErr++;
            System.out.println("isHeapAfterDeleteMinErr");

        }
        minVal = heap.getMin();
        if ( minVal != 9)
        {
            getMinErr++;
            System.out.println("getMinErr: getMin returns " + minVal + " instead of 9");
        }

        System.out.println("deleteMin" );
        heap.deleteMin();     
        heapsize--;
        outputheap(heap);
        if (heap.isHeap() != true )
        {
            isHeapAfterDeleteMinErr++;
            System.out.println("isHeapAfterDeleteMinErr");

        }
        
        System.out.println("Insert 2" );
        heap.insert(2);
        heapsize++;
        System.out.println("Insert 6" );
        heap.insert(6);
        heapsize++;
        System.out.println("Insert 5" );
        heap.insert(5);
        heapsize++;
        System.out.println("Insert 4" );
        heap.insert(4);
        heapsize++;
        System.out.println("Insert 7" );
        heap.insert(7);
        heapsize++;
        System.out.println("Insert 8" );
        heap.insert(8);
        heapsize++;
        System.out.println("Insert 9" );
        heap.insert(9);
        heapsize++;
        
        
        System.out.println("Insert 4" );
        heap.insert(4);
        heapsize++;
        outputheap(heap);
        
        if (heap.isHeap() != true )
        {
            isHeapAfterInsertErr++;
            System.out.println("isHeapAfterInsertError");
        }
        System.out.println("Melding Heaps: ");
        Heap heap2 = new Heap();
        heap2.insert(1);
        heap2.insert(2);
        heap2.insert(3);
        heap2.insert(4);
        heap2.insert(5);
        heap2.insert(3);
        heap2.insert(1);
        heap.meld(heap2);
        outputheap(heap);
        outputheap(heap2);
        
        
        
        
        
        System.out.println("Delete Min" );
        heap.deleteMin();
        heapsize--;
        outputheap(heap);
        if (heap.isHeap() != true )
        {
            isHeapAfterDeleteMinErr++;
            System.out.println("isHeapAfterDeleteMinError");
        }
      
        System.out.println("Delete Min" );
        heap.deleteMin();
        heapsize--;
        outputheap(heap);
        if (heap.isHeap() != true )
        {
            isHeapAfterDeleteMinErr++;
            System.out.println("isHeapAfterDeleteMinError");
        }
        System.out.println("Delete Min" );
        heap.deleteMin();
        heapsize--;
        outputheap(heap);
        if (heap.isHeap() != true )
        {
            isHeapAfterDeleteMinErr++;
            System.out.println("isHeapAfterDeleteMinError");
        }
        System.out.println("Delete Min" );
        heap.deleteMin();
        heapsize--;
        outputheap(heap);
        if (heap.isHeap() != true )
        {
            isHeapAfterDeleteMinErr++;
            System.out.println("isHeapAfterDeleteMinError");
        }
        System.out.println("Delete Min" );
        heap.deleteMin();
        heapsize--;
        outputheap(heap);
        if (heap.isHeap() != true )
        {
            isHeapAfterDeleteMinErr++;
            System.out.println("isHeapAfterDeleteMinError");
        }
      
        
        
        
        


        if (isHeapAfterInsertErr > 0)
        {
            System.out.println("Num of isHeap fails after Insert = " + isHeapAfterInsertErr);
        }
        if (isHeapAfterDeleteMinErr > 0)
        {
            System.out.println("Num of isHeap fails after deleteMin = " + isHeapAfterDeleteMinErr);
        }
        if (getMinErr > 0)
        {
            System.out.println("Num of getMin fails = " + getMinErr);
        }
        if (isHeapAfterDeleteMinErr > 0)
        {
            System.out.println("Num of isHeap fails after DeleteMin = " + isHeapAfterDeleteMinErr);
        }


        System.out.println("End of tests");
    }

}
